#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct linklist{
    char data[3];
    struct linklist *pr;
}link;

link* creatandinsertlinklist(link *head,char s[3]);

void distribute(link *mother,link *sona,link *sonb,link *sonc);
void showlinklista(link *head);
void showlinklistb(link *head);
void showlinklistc(link *head);

int countnum(link* head);
link* sortnum(link* head,int count);



int main()
{
    link *mother=NULL,*sona=NULL,*sonb=NULL,*sonc=NULL;
    char s[3];
    scanf("%s",s);
    while(s[0]!='-'||s[1]!='1')
    {
       mother=creatandinsertlinklist(mother,s);
       scanf("%s",s);
    }
    distribute(mother,sona,sonb,sonc);
    
    return 0;
    

}


link* creatandinsertlinklist(link *head,char s[3])
{
    link *temp=head;
    if(head==NULL){
        head=(link*)malloc(sizeof(link));
        for(int i=0;i<3;i++)
        {
            head->data[i]=s[i];
        }
        head->pr=NULL;   
    }
    else{
        while(temp->pr!=NULL)
        {
            temp=temp->pr;
        }
        temp->pr=(link*)malloc(sizeof(link));
        temp=temp->pr;
        for(int i=0;i<3;i++)
        {
            temp->data[i]=s[i];
        };
        temp->pr=NULL;
    }
    return head;
}

void showlinklista(link *head)
{
    
    link *temp=head;
    if(head==NULL)
    {
        printf("There is no item in A list.\n");
    }
    else{
        printf("The list A is: ");
        while(temp->pr!=NULL)
        {
            printf("%c ",temp->data[0]);
            temp=temp->pr;
            
        }
        printf("%c\n",temp->data[0]);
    }
}
void showlinklistb(link *head)
{
    
    link *temp=head;
    if(head==NULL)
    {
        printf("There is no item in B list.\n");
    }
    else{
        printf("The list B is: ");
        while(temp->pr!=NULL)
        {
            printf("%c ",temp->data[0]);
            temp=temp->pr;
            
        }
        printf("%c\n",temp->data[0]);
    }
}
void showlinklistc(link *head)
{
    
    link *temp=head;
    if(head==NULL)
    {
        printf("There is no item in C list.");
    }
    else{
        printf("The list C is: ");
        while(temp->pr!=NULL)
        {
            printf("%c ",temp->data[0]);
            temp=temp->pr;
           
        }
        printf("%c",temp->data[0]);
    }
}


void distribute(link *mother,link *sona,link *sonb,link *sonc)
{
    link *virtualmotherhead=(link*)malloc(sizeof(link));
    for(int i=0;i<3;i++)
    {
        virtualmotherhead->data[i]=0;
    }
    virtualmotherhead->pr=mother;
    while(virtualmotherhead->pr!=NULL)
    {
        link *next=virtualmotherhead->pr;
        char x=next->data[0];
        if(x>=48&&x<=57)
        {
            link *temp=sonb;
            if(sonb==NULL)
            {
                link *temp2=next->pr;
                sonb=next;
                next->pr=NULL;
                virtualmotherhead->pr=temp2;
            }
            else{
                while(temp->pr!=NULL)
                {
                    temp=temp->pr;
                }
                link *temp2=next->pr;
                temp->pr=next;
                next->pr=NULL;
                virtualmotherhead->pr=temp2;
            }
        }
        else if(x>=65&&x<=90||x>=97&&x<=122)
        {
             link *temp=sona;
            if(sona==NULL)
            {
                link *temp2=next->pr;
                sona=next;
                next->pr=NULL;
                virtualmotherhead->pr=temp2;
            }
            else{
                while(temp->pr!=NULL)
                {
                    temp=temp->pr;
                }
                link *temp2=next->pr;
                temp->pr=next;
                next->pr=NULL;
                virtualmotherhead->pr=temp2;
            }
        }
        else 
        {
            link *temp=sonc;
            if(sonc==NULL)
            {
                link *temp2=next->pr;
                sonc=next;
                next->pr=NULL;
                virtualmotherhead->pr=temp2;
            }
            else{
                while(temp->pr!=NULL)
                {
                    temp=temp->pr;
                }
                link *temp2=next->pr;
                temp->pr=next;
                next->pr=NULL;
                virtualmotherhead->pr=temp2;
            }
        }
    }
    sona=sortnum(sona,countnum(sona));
    sonb=sortnum(sonb,countnum(sonb));
    sonc=sortnum(sonc,countnum(sonc));

    showlinklista(sona);
    showlinklistb(sonb);
    showlinklistc(sonc);

    

}

int countnum(link* head)
{
    int ret=1;
    if(head==NULL)
    {
        return 1;
    }
    else {
        while(head->pr!=NULL)
    {
        ret++;
        head=head->pr;
    }
    return ret;
    }
}

link* sortnum(link* head,int count)
{
    if(count==1)
    {
        return head;
    }
    else if(count==2)
    {
        link* temp1,*temp2;
        temp1=head;
        temp2=head->pr;
        if(head->data[0]>temp2->data[0])
        {
            head=temp2;
            temp2->pr=temp1;
            temp1->pr=NULL;
        }
        return head;
    }
    else 
    {
        link *current,*temp1,*temp2;
        int flag=1;
        for(;count>1;count--)
        {
            current=head;
            temp1=current->pr;
            flag=1;
            while(temp1->pr!=NULL)
            {

                temp2=temp1->pr;
                if(flag==1)
                {
                    if(current->data[0]>temp1->data[0])
                    {
                        head=temp1;
                        current->pr=temp1->pr;
                        temp1->pr=current;
                        current=head;
                        temp1=current->pr;
                    }
                   
                    flag=0;
                }
                else
                {
                    if(temp1->data[0]>temp2->data[0])
                    {
                        current->pr=temp2;
                        temp1->pr=temp2->pr;
                        temp2->pr=temp1;
                        current=current->pr;
                    }
                    else
                    {
                        current=current->pr;
                        temp1=temp1->pr;
                    }
                }

            }
        }
        return head;
    }
}